var proColumns = [{
	id: 'proType',
	title: '项目类型',
	type: 'string',
	width: 75,
	columnClass: 'text-center',
	resolution: function (value) {
		var content = '';
		if (value == "XS") {
			content += '销售类';
		} else if (value == "ZL") {
			content += '战略类';
		} else if (value == "YF") {
			content += '研发类';
		} else if (value == "BM") {
			content += '部门类';
		} else if (value == "SW") {
			content += '事务类';
		} else {
			content += '测试类';
		}
		return content;
	}
}, {
	id: 'proName',
	title: '项目名称',
	type: 'string',
	columnClass: 'text-center',
}, {
	id: 'myJob',
	title: '我的角色',
	type: 'string',
	columnClass: 'text-center',
}, {
	id: 'proLv',
	title: '优先级',
	type: 'string',
	width: 60,
	columnClass: 'text-center',
	resolution: function (value) {
		var content = '';
		if (value == 1) {
			content += '低';
		}
		if (value == 2) {
			content += '中';
		}
		if (value == 3) {
			content += '高';
		}
		return content;
	}
}, {
	id: 'stageCode',
	title: '当前阶段',
	type: 'string',
	width: 75,
	columnClass: 'text-center',
    resolution: function (value) {
        var content = '';
        if (value == 1) {
            content += '线索阶段';
        }
        if (value == 2||value == 3) {
            content += '运作阶段';
        }
        if (value == 4) {
            content += '合同阶段';
        }
        if (value == 5) {
            content += '交付阶段';
        }
        if (value == 6) {
            content += '回款阶段';
        }
        return content;
    }
}, {
	id: 'proState',
	title: '状态',
	type: 'string',
	width: 80,
	codeTable: status,
	hideType: 'sm|xs',
	columnClass: 'text-center',
	resolution: function (value) {
		var content = '';
		if (value == 1) {
			content += '<span style="background:#5bc0de;padding:2px 10px;color:white;">运行中</span>';
		}
		if (value == 2) {
			content += '<span style="background:#d9534f;padding:2px 10px;color:white;">已关闭</span>';
		}
		if (value == 3) {
			content += '<span style="background:#5cb85c;padding:2px 10px;color:white;">已完结</span>';
		}
		if (value == 4) {
			content += '<span style="background:#f8d347;padding:2px 10px;color:white;">已暂停</span>';
		}
		return content;
	}
}, {
	id: 'operation',
	title: '操作',
	width: 130,
	type: 'string',
	columnClass: 'text-center',
	resolution: function (value, record) {
		var content = '';
		content += '<a class="btn btn-xs btn-primary" onclick="findJzdp(' + record.id + ')"><i class="icon-eye-open"> 点评</i></a>';
		content += '  ';
		content += '<button class="btn btn-xs btn-warning" onclick="progress(' + record.id + ');"><i class="icon-retweet"></i>  进展</button>';
		// content += '<button class="btn btn-xs btn-info" onclick="edit(' + record.id + ');"><i class="fa fa-edit"></i>  编辑</button>';
		// content += '  ';
		// content += '<button class="btn btn-xs btn-danger" onclick="delete (' + record.id + ');"><i class="fa fa-trash-o"></i>删除</button>';
		return content;
	}
}];

function findSysjzs(CertusJsonAjax, CertusFormAjax) {
	CertusJsonAjax.dataInit("findSysProjz", {}, proColumns,
		'proContainer2', 'proToolBarContainer2', 20);

	this.findJzdp = function (proId) {
		CertusFormAjax.ajax('findProJzdp', { "proId": proId }, function (response) {
			var data = response.data;
			if (data.length != 0) {
				var content = '<div class="review-middle">';
				content += '<ul class="layui-timeline">';
				for (var i = 0; i < data.length; i++) {
					var ftime = new Date(data[i].create_time);
					ftime = $.fn.dlshouwen.grid.tools.dateFormat(ftime, "yyyy-MM-dd hh:mm:ss");

					content += '<li class="layui-timeline-item">'+
					'<i class="layui-icon layui-timeline-axis"></i>'+
					'<div class="layui-timeline-content layui-text">'+
						'<h3 class="layui-timeline-title">点评时间：' + ftime + '&nbsp;&nbsp;|&nbsp;&nbsp;点评人：' + data[i].user_name + '</h3>'+
						'<dl>'+
							'<dd><h5>项目进展:</h5><p>' + data[i].content + '</p></dd>'+
							'<dd><h5>下一步计划:</h5><p>' + data[i].next_step + '</p></dd>'+
							'<dd><h5>点评内容:</h5><p>' + data[i].comments + '</p></dd>'+
						'</dl>'+
					'</div>'+
				'</li>';


					// content += '<h1 class="blue">时间：' + ftime + " | " + '提交人：' + data[i].user_name + '</h1>'
					// content += '<ul>';
					// content += '<li>项目进展：<p>' + data[i].content + '</p></li>'
					// content += '<li>下一步计划:<p>' + data[i].next_step + '</p></li>'
					// content += '<li>点评内容:<p>' + data[i].comments + '</p></li>'
					// content += '</ul>'
				}
				content += '</ul></div>';
				layer.open({
					type: 1,
					skin: 'layui-layer-demo', //样式类名
					area: ['550px', '500px'], //宽高
					closeBtn: 1, //不显示关闭按钮
					anim: 2,
					title: '项目进展点评记录',
					shadeClose: true, //开启遮罩关闭
					content: content
				});
			} else {
				layer.msg("无点评数据！");
			}
		});
	}
}
function add1(id) {
	location.href = "#/addJz/" + id;
}
//跳转到项目进展
function progress(id) {
	var param = id + "_" + 1;
	location.href = '#/toProinfo/' + param;
}

function findJzlist(CertusFormAjax, $routeParams) {
	var proColumns = [{
		id: 'content',
		title: '进展内容',
		type: 'string',
		columnClass: 'text-center'
	}, {
		id: 'next_step',
		title: '下一步计划',
		type: 'string',
		columnClass: 'text-center'
	}, {
		id: 'begin_time',
		title: '开始时间',
		type: 'date',
		format: 'yyyy-MM-dd',
		otype: 'time_stamp_ms',
		columnClass: 'text-center',
	}, {
		id: 'end_time',
		title: '结束时间',
		type: 'date',
		format: 'yyyy-MM-dd',
		otype: 'time_stamp_ms',
		columnClass: 'text-center'
	}, {
		id: 'operation',
		title: '操作',
		width: 130,
		type: 'string',
		columnClass: 'text-center',
		resolution: function (value, record) {
			var content = '';
			//计算相差多少天
			var d = new Date();
			start = record.createTime.replace(/-/g, "/");
			var startdate = new Date(start);
			var time = d.getTime() - startdate.getTime();
			var days = parseInt(time / (1000 * 60 * 60 * 24));
			//大于三天则不能修改和删除
			if (days <= 3) {
				content += '<button class="btn btn-xs btn-info" onclick="edit(' + record.id + ');"><i class="fa fa-edit"></i>  编辑</button>';
				content += ' ';
				content += '<button class="btn btn-xs btn-danger" onclick="del(' + record.id + ');"><i class="fa fa-trash-o"></i>删除</button>';
			}
			return content;
		}
	}];
	CertusFormAjax.ajax('findReportlists', { "proId": $routeParams.id }, function (response) {
		var data = response.data;
		var telOption = {
			lang: 'zh-cn',
			ajaxLoad: false,
			extraWidth: 20,
			exportFileName: '进展列表',
			datas: data,
			columns: proColumns,
			gridContainer: 'proContainer3',
			toolbarContainer: 'proToolBarContainer3',
			tools: '',
			pageSize: 10,
			pageSizeLimit: [10, 15, 20]
		};
		var telGrid = $.fn.dlshouwen.grid.init(telOption);
		telGrid.load();
	});

	this.edit = function (id) {
		location.href = "#/editJz/" + id;
	}

	this.add = function () {
		location.href = "#/addJz/" + $routeParams.id;
	}


	this.del = function (id) {
		CertusFormAjax.ajax('delReport', { "id": id, "projId": $routeParams.id }, function () {
			window.location.reload();
		});
	}
}